﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CCodeTreeLib;
using SqlOrm.Xml;

namespace SqlOrm.TreeBuilders
{
    public class ServiceBusinessLogicTreeBuilder: CCodeTree
    {
        DataDictionary _ddl;
        SqlContextTreeBuilder _context;
        public ServiceBusinessLogicTreeBuilder(DataDictionary ddl, SqlContextTreeBuilder context)
        {
            _context = context;
            _ddl = ddl;
            Build();
        }

        private void Build()
        {
            var ns = AddStatement(new CCodeNamespace(_ddl.Settings.ServiceContractOutput.clrnamespace));
            Usings.Add(new CCodeUsing("System"));
            Usings.Add(new CCodeUsing("System.Net.Security"));
            Usings.Add(new CCodeUsing("System.ServiceModel"));

            if (_ddl.Settings.ServiceContractOutput.clrnamespace != _ddl.Settings.DataContractOutput.clrnamespace)
                Usings.Add(new CCodeUsing(_ddl.Settings.DataContractOutput.clrnamespace));
            Usings.Add(new CCodeUsing("System.Collections.Generic"));


            var si = new CCodeInterface(string.Format("I{0}ServiceContract", _ddl.Settings.ServiceContractOutput.ServiceName));
            si.Modifier = Modifier.Public;

            ns.AddInterface(si);
            si.Attributes.Add(new CCodeAttribute("ServiceContract", string.Format("Namespace = \"{0}\",  SessionMode = SessionMode.Allowed, ProtectionLevel = ProtectionLevel.None ", _ddl.Settings.ServiceContractOutput.urinamespace)));

            var methods = _context.OfType<CCodeMethod>();
            foreach (var method in methods)
            {

            }
        }
    }
}
